import {
  Controller,
  Get,
  Post,
  Body,
  Patch,
  Param,
  Delete,
  Req,
  UseGuards,
  Query,
} from '@nestjs/common';
import { SpecialColumnService } from './special-column.service';
import { CreateSpecialColumnDto } from './dto/create-special-column.dto';
import { UpdateSpecialColumnDto } from './dto/update-special-column.dto';
import {
  ApiOperation,
  ApiTags,
  ApiBody,
  ApiResponse,
  ApiParam,
} from '@nestjs/swagger';
import { ListArticleColumnDto } from './dto/list-article-column.dto';
import { ArticleColumnInclusionDto } from './dto/article-column-inclusion.dto';
import { Roles } from 'src/user/roles.decorator';
import { RolesGuard } from 'src/user/roles.guard';

@Controller('specialColumn')
@UseGuards(RolesGuard)
@ApiTags('专栏管理')
export class SpecialColumnController {
  constructor(private readonly specialColumnService: SpecialColumnService) {}

  @Post()
  @Roles('systemAdmin', 'admin', 'user')
  @ApiOperation({
    summary: '创建专栏',
    description: '创建专栏',
  })
  @ApiBody({ type: CreateSpecialColumnDto })
  @ApiResponse({ status: 200, description: '创建成功' })
  create(@Body() createSpecialColumnDto: CreateSpecialColumnDto, @Req() req) {
    return this.specialColumnService.create(createSpecialColumnDto, req);
  }

  @Get()
  @ApiOperation({
    summary: '专栏列表查询',
    description: '专栏列表查询',
  })
  @ApiResponse({ status: 200, description: '查询成功' })
  findAll() {
    return this.specialColumnService.findAll();
  }

  @Get('columnListForSelect')
  @ApiOperation({
    summary: '专栏列表下拉项',
    description: '专栏列表下拉项',
  })
  @ApiResponse({ status: 200, description: '查询成功' })
  findAllForSelect() {
    return this.specialColumnService.findAllForSelect();
  }

  @Get(':id')
  @ApiOperation({
    summary: '根据ID查询专栏',
    description: '根据ID查询专栏',
  })
  @ApiParam({ name: 'id', description: '专栏id' })
  @ApiResponse({ status: 200, description: '查询成功' })
  findOne(@Param('id') id: string) {
    return this.specialColumnService.findOne(+id);
  }

  @Patch(':id')
  @ApiOperation({
    summary: '根据ID修改专栏',
    description: '根据ID修改专栏',
  })
  @ApiParam({ name: 'id', description: '专栏id' })
  @ApiBody({ type: UpdateSpecialColumnDto })
  @ApiResponse({ status: 200, description: '修改专栏成功' })
  update(
    @Param('id') id: string,
    @Body() updateSpecialColumnDto: UpdateSpecialColumnDto,
    @Req() req,
  ) {
    return this.specialColumnService.update(+id, updateSpecialColumnDto, req);
  }

  @Delete(':id')
  @Roles('systemAdmin', 'admin', 'user')
  @ApiOperation({
    summary: '删除专栏',
    description: '根据id删除专栏',
  })
  @ApiParam({ name: 'id', description: '专栏id' })
  @ApiResponse({ status: 200, description: '删除专栏成功' })
  remove(@Param('id') id: string, @Req() req) {
    return this.specialColumnService.softDeleteColumn(+id, req);
  }

  @Get('queryArticleListByColumnId/:id')
  @ApiOperation({
    summary: '根据专栏id查询文章列表',
    description: '根据专栏id查询文章列表',
  })
  @ApiParam({ name: 'id', description: '专栏id' })
  @ApiBody({ type: ListArticleColumnDto })
  @ApiResponse({ status: 200, description: '查询成功' })
  queryArticleListByColumnId(
    @Param('id') id: string,
    @Query() query: ListArticleColumnDto,
  ) {
    return this.specialColumnService.queryArticleListByColumnId(+id, query);
  }

  @Get('queryOtherArticleListByColumnId/:id')
  @ApiOperation({
    summary: '查询非该专栏的文章列表',
    description: '根据专栏id查询非该专栏的文章列表',
  })
  @ApiParam({ name: 'id', description: '专栏id' })
  @ApiBody({ type: ListArticleColumnDto })
  @ApiResponse({ status: 200, description: '查询成功' })
  queryOtherArticleListByColumnId(
    @Param('id') id: string,
    @Query() query: ListArticleColumnDto,
  ) {
    return this.specialColumnService.queryOtherArticleListByColumnId(
      +id,
      query,
    );
  }

  @Post('cancelArticleInclusion')
  @Roles('systemAdmin', 'admin', 'user')
  @ApiOperation({
    summary: '批量取消收录',
    description: '批量取消收录至该专栏',
  })
  @ApiBody({ type: ArticleColumnInclusionDto })
  @ApiResponse({ status: 200, description: '查询成功' })
  cancelArticleInclusion(@Body() body: ArticleColumnInclusionDto) {
    return this.specialColumnService.cancelArticleInclusion(body);
  }

  @Post('addArticleInclusion')
  @Roles('systemAdmin', 'admin', 'user')
  @ApiOperation({
    summary: '文章批量收录',
    description: '文章批量收录至该专栏',
  })
  @ApiBody({ type: ArticleColumnInclusionDto })
  @ApiResponse({ status: 200, description: '查询成功' })
  addArticleInclusion(@Body() body: ArticleColumnInclusionDto) {
    return this.specialColumnService.addArticleInclusion(body);
  }
}
